angular.module('loginModule', [])
    .controller('loginCtr', ['$scope', '$rootScope', '$location', function ($scope, $rootScope, $location) {
        $scope.topTitle = '登录';
        $scope.register = '注册';
        $scope.moreType = '更多登录方式';
        $scope.isUserBool=false;
        $scope.isPswBool=false;
        var userData=LsyStorage.getItem('userDatas');
        userData=userData?userData:[];
        $scope.isUser=function(user){
            $scope.isUserBool=false;
            if(user){
                for(var i=0;i<userData.length;i++){
                    if(user==userData[i].user){
                        $scope.isUserBool=false;
                        $scope.userInformation=userData[i];
                        break;
                    }else {
                        $scope.isUserBool=true;
                    }
                }
            }
        };
        $scope.login = function (psw) {
            $scope.isPswBool=false;
            if(psw && !$scope.isUserBool){
                if(psw==$scope.userInformation.psw){
                    $scope.isPswBool=false;
                }else {
                    $scope.isPswBool=true;
                }
            }
            if (!$scope.isUserBool && !$scope.isPswBool) {
                alert('登录成功！');
                $rootScope.loginUser = $scope.user; //根作用域来跨页面展示登录用户
                LsyCookie.setItem('userLogin',$scope.user,1200000);
                $location.path('/home'); //angularjs操作url，不填值表示获取，括号内有内容表示设置并根据内容进行跳转
            }
        };

    }]);